home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15518 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.cern.ch!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is wrong with this loop?
  5. Date: 19 Apr 96 15:53:21 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.829929201@news.cern.ch>
  8. References: <4l86la$1t9@uwm.edu>
  9. NNTP-Posting-Host: hpplus01.cern.ch
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=US-ASCII
  12. Content-Transfer-Encoding: 7bit
  13. X-Newsreader: NN version 6.5.0 #18 (NOV)
  14.  
  15. In <4l86la$1t9@uwm.edu> mardavuy@alpha2.csd.uwm.edu (Mario David Uy) writes:
  16.  
  17. >#include <stdio.h>
  18. >int main(void)
  19. >{
  20. >   int dia;
  21. >
  22. >   char cd;
  23. >
  24. >   ...
  25. >
  26. >   scanf("%c", &cd);
  27. >   while (cd != 'm' || cd ! 'f' || cd != 'o')
  28. >    {
  29. >    printf("Re-enter m, f, or o.\n");
  30. >    scanf(%c", &cd);
  31. >    }
  32. >   ...
  33. >}
  34. >
  35. >It works fine, except that it gives me the printf() twice.
  36.  
  37. It gives you the printf() twice because this is precisely what you were
  38. asking for.  Hint: you forgot to drop the newline from stdin.
  39.  
  40. BTW, using scanf to get user input will cause even more shots in your
  41. foot in the future :-)
  42.  
  43. Dan
  44. --
  45. Dan Pop
  46. CERN, CN Division
  47. Email: danpop@mail.cern.ch 
  48. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  49.